Skip to content

Iteration

while Loops

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Represent iterative processes using a while loop.

ESSENTIAL KNOWLEDGE

  • Iteration statements change the flow of control by repeating a set of statements zero or more times until a condition is met.

  • In loops, the Boolean expression is evaluated before each iteration of the loop body, including the first. When the expression evaluates to true, the loop body is executed. This continues until the expression evaluates to false, whereupon the iteration ceases.

  • A loop is an infinite loop when the Boolean expression always evaluates to true.

  • If the Boolean expression evaluates to false initially, the loop body is not executed at all.

  • Executing a return statement inside an iteration statement will halt the loop and exit the method or constructor.

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

For algorithms in the context of a particular specification that does not require the use of traversals:

  • Identify standard algorithms.
  • Modify standard algorithms.
  • Develop an algorithm.

ESSENTIAL KNOWLEDGE

  • There are standard algorithms to:

    • Identify if an integer is or is not evenly divisible by another integer
    • Identify the individual digits in an integer
    • Determine the frequency with which a specific criterion is met
  • There are standard algorithms to:

    • Determine a minimum or maximum value
    • Compute a sum, average, or mode

for Loops

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Represent iterative processes using a for loop.

ESSENTIAL KNOWLEDGE

  • There are three parts in a for loop header: the initialization, the Boolean expression, and the increment. The increment statement can also be a decrement statement.

  • In a for loop, the initialization statement is only executed once before the first Boolean expression evaluation. The variable being initialized is referred to as a loop control variable.

  • In each iteration of a for loop, the increment statement is executed after the entire loop body is executed and before the Boolean expression is evaluated again.

  • A for loop can be rewritten into an equivalent while loop and vice versa.

  • “Off by one” errors occur when the iteration statement loops one time too many or one time too few.

Developing Algorithms Using Strings

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

For algorithms in the context of a particular specification that involves String objects:

  • Identify standard algorithms.
  • Modify standard algorithms.
  • Develop an algorithm.

ESSENTIAL KNOWLEDGE

  • There are standard algorithms that utilize String traversals to:
    • Find if one or more substrings has a particular property
    • Determine the number of substrings that meet specific criteria
    • Create a new string with the characters reversed

Nested Iteration

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Represent nested iterative processes.

ESSENTIAL KNOWLEDGE

  • Nested iteration statements are iteration statements that appear in the body of another iteration statement.

  • When a loop is nested inside another loop, the inner loop must complete all its iterations before the outer loop can continue.

Informal Code Analysis

ENDURING UNDERSTANDING

LEARNING OBJECTIVE

Compute statement execution counts and informal run-time comparison of iterative statements.

ESSENTIAL KNOWLEDGE

  • A statement execution count indicates the number of times a statement is executed by the program.